package com.apchernykh.types;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.apchernykh.rozhlasapp.utils.ConditionalLog;



public class PodcastFeedInfo {

	private String mTitle;
	private String mDescription;
	private String mUrl;
	
	private List<Show> mShows = new ArrayList<Show>();

	public PodcastFeedInfo(String iTitle, String iUrl) {
		this.mTitle = iTitle;
		this.mUrl = iUrl;
	}

	public String getTitle() {
		return mTitle;
	}

	
	final static Pattern mStationNamePattern = Pattern.compile("\\(?.esk. rozhlas[ -]*\\)?");

	public void setTitle(String iTitle) {
		String aTitle = iTitle;
		try {
			Matcher aStationNameMatch = mStationNamePattern.matcher(aTitle);
			aTitle = aStationNameMatch.replaceAll("");
		} catch (IllegalStateException e) {
			ConditionalLog.e("could not strip date from string "
					+ aTitle);
		}

		this.mTitle = aTitle.trim();
	}

	public String getDescription() {
		return mDescription;
	}

	public void setDescription(String iDescription) {
		this.mDescription = iDescription.trim();
	}

	public List<Show> getShows() {
		return mShows;
	}

	public void setShows(List<Show> iShows) {
		if(iShows == null)
		{
			//we cannot afford having shows as null, since it is fed to native android gui elements
			this.mShows = new ArrayList<Show>();
		}
		this.mShows = iShows;
	}

	public String getUrl() {
		return mUrl;
	}

	public void setUrl(String iUrl) {
		this.mUrl = iUrl;
	}

	@Override
	public String toString() {
		StringBuilder aStringBuilder = new StringBuilder();
		aStringBuilder.append("Podcast(");
		aStringBuilder.append("title='");
		aStringBuilder.append(mTitle);
		aStringBuilder.append("',description='");
		aStringBuilder.append(mDescription);
		aStringBuilder.append("',url='");
		aStringBuilder.append(mUrl);
		aStringBuilder.append("',shows=[");
		boolean aFirst = true;
		for (Show aCurrentShow : mShows) {
			if (!aFirst) 
			{
				aStringBuilder.append(",");
			}
			aStringBuilder.append(aCurrentShow.toString());
			aFirst = false;
		}
		aStringBuilder.append("]");
		aStringBuilder.append(")");
		return aStringBuilder.toString();
	}
	
}